package com.service.Impl;

import com.dao.ArticleTypeMapper;
import com.entity.pojo.ArticleType;
import com.entity.vo.ArticlePage;
import com.entity.vo.ArticleTypePage;
import com.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleTypeServiceImpl implements ArticleTypeService {
    @Autowired
    private ArticleTypeMapper articleTypeMapper;

    @Override
    public List<ArticleType> findType() {
        return articleTypeMapper.findType();
    }

    @Override
    public ArticleTypePage findByPage(Integer currentPage, Integer rows, String newsTitle, Byte newsState) {
        ArticleTypePage articleTypePage = new ArticleTypePage();
        //每页几条
        articleTypePage.setRows(rows);
        //总条数
        int count = articleTypeMapper.findArticleTotalCount(newsTitle,newsState);
        articleTypePage.setTotalCount(count);

        int start=(currentPage-1)*rows;
        //每页的记录
        articleTypePage.setList(articleTypeMapper.getAll(start,rows,newsState,newsTitle) );
        //总页数
        articleTypePage.setTotalPage((count%rows==0)?(count/rows):(count/rows+1));
        //当前页
        articleTypePage.setCurrentPage(currentPage);
        return articleTypePage;
    }

    @Override
    public List<ArticleType> SelectAll() {
        return articleTypeMapper.SelectAll();
    }


}
